package com.juku2024.juku.db.converter

import android.text.TextUtils
import androidx.room.TypeConverter
import com.google.gson.Gson
import com.juku2024.juku.db.entity.VideoEpisodeEntity
import com.juku2024.juku.tools.TypeUtils

class VideoEpisodeConverters {

    @TypeConverter
    fun stringToList(value: String?): ArrayList<VideoEpisodeEntity>? {
        return if (TextUtils.isEmpty(value)) {
            null
        } else {
            TypeUtils.getListByString(value!!, VideoEpisodeEntity::class.java)
        }

    }

    @TypeConverter
    fun listToString(list: ArrayList<VideoEpisodeEntity>?): String? {
        return if (list?.isNotEmpty() == true) {
            Gson().toJson(list)
        } else {
            null
        }
    }

}